#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4 + 10, INF = 1e8;
int n;
int arr[N];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int minv = INF, maxv = -INF;
		for (int j = i; j < n; j++) {
			minv = min(minv, arr[j]);
			maxv = max(maxv, arr[j]);
			if (maxv - minv == j - i) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}